package com.zbj.nacos.consumer;

import com.zbj.nacos.consumer.service.ConfigService;
import com.zbj.nacos.consumer.service.ProviderClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

/**
 * TestController
 *
 * @author weigang
 * @create 2019-07-25
 **/
@RestController
@RequestMapping("/consumer")
public class TestController {

    private RestTemplate restTemplate;

    @Autowired
    private ProviderClient providerClient;


    @Autowired
    private ConfigService configService;

    @Autowired
    public TestController(RestTemplate restTemplate) {
        this.restTemplate = restTemplate;
    }

    @RequestMapping(value = "/{str}", method = RequestMethod.GET)
    public String echo(@PathVariable String str) {
        return providerClient.hello(str);
    }


    @GetMapping("/demo")
    public String demo() {
        System.out.println("configService:"+configService);
        return configService.getMyName();
    }

    @RequestMapping(value = "/get/{str}", method = RequestMethod.GET)
    public String get(@PathVariable String str) {
        return restTemplate.getForObject("http://nacos-provider/provider/" + str, String.class);
    }
}